home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / RMIClassLoader.java < prev    next >
Text File  |  1998-09-22  |  3KB  |  97 lines

  1. /*
  2.  * @(#)RMIClassLoader.java    1.11 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.rmi.server;
  16.  
  17. import java.net.MalformedURLException;
  18. import java.net.URL;
  19.  
  20. /**
  21.  * The RMIClassLoader class provides static methods for loading classes
  22.  * over the network.  Classes can be loaded from either a particular URL,
  23.  * or from the URL specified in the <b>java.rmi.server.codebase</b>
  24.  * system property.
  25.  * 
  26.  * @version    1.11, 07/01/98
  27.  * @author Ann Wollrath
  28.  */
  29. public class RMIClassLoader {
  30.     /*
  31.      * Disallow anyone from creating one of these.
  32.      */
  33.     private RMIClassLoader() {}
  34.  
  35.     private static LoaderHandler handler = null;
  36.  
  37.     private static synchronized LoaderHandler getHandler() 
  38.     {
  39.     if (handler == null) {
  40.         try {
  41.         Class cl = Class.forName(LoaderHandler.packagePrefix +
  42.                      ".LoaderHandler");
  43.         handler = (LoaderHandler)cl.newInstance();
  44.         } catch (Exception e) {
  45.         throw new Error("No LoaderHandler present");
  46.         }
  47.     }
  48.     return handler;
  49.     }
  50.  
  51.     /**
  52.      * Load a class from the URL specified in the
  53.      * <b>java.rmi.server.codebase</b> property.
  54.      * @param name  the name of the class to load
  55.      * @return the Class object representing the loaded class
  56.      * @exception MalformedURLException
  57.      *            The system property <b>java.rmi.server.codebase</b>
  58.      *            does not contain a valid URL.
  59.      * @exception ClassNotFoundException
  60.      *            A definition for the class could not
  61.      *            be found at the codebase URL.
  62.      */
  63.     public static Class loadClass(String name)
  64.     throws MalformedURLException, ClassNotFoundException
  65.     {
  66.     return getHandler().loadClass(name);
  67.     }
  68.     
  69.     /**
  70.      * Load a class from a URL.
  71.      * @param codebase  the URL from which to load the class
  72.      * @param name      the name of the class to load
  73.      * @return the Class object representing the loaded class
  74.      * @exception MalformedURLException
  75.      *            The codebase paramater was null.
  76.      * @exception ClassNotFoundException
  77.      *            A definition for the class could not
  78.      *            be found at the specified URL.
  79.      */
  80.     public static Class loadClass(URL codebase, String name)
  81.     throws MalformedURLException, ClassNotFoundException
  82.     {
  83.     return getHandler().loadClass(codebase, name);
  84.     }
  85.  
  86.     /**
  87.      * Returns the security context of the given class loader
  88.      * @param loader a class loader from which to get the security
  89.      *           context
  90.      * @return the security context (e.g., a URL)
  91.      */
  92.     public static Object getSecurityContext(ClassLoader loader)
  93.     {
  94.     return getHandler().getSecurityContext(loader);
  95.     }
  96. }
  97.